package com.atguigu.day21.bytestream;

import org.junit.Test;

import java.io.*;
import java.nio.Buffer;

/**
 * @version 1.0
 * @Author 马冰
 * @Date 2024/11/26 11:34
 * @注释
 */
public class Exer {


    @Test
    public void test02(){

        try (
                InputStream is = new FileInputStream("D:\\c1.jpg");
                OutputStream os = new FileOutputStream("D:\\Games\\c2.jpg")) {

            //创建数组
            byte[] buffer = new byte[1024];
            /*//写入资源
            is.read(buffer);
            os.write(buffer);*/
            int length = 0;
            //循环读写
            while ((length = is.read(buffer)) != -1){
                os.write(buffer, 0, length);
            }
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    @Test
    public void test01() throws Exception {
        //源文件位置
        InputStream is = new FileInputStream("D:\\c1.jpg");
        //
        byte[] bytes = new byte[is.available()];
        int read = is.read(bytes);

        OutputStream os = new FileOutputStream("D:\\Games\\c1.jpg");

        os.write(bytes, 0, read);

        is.close();
        os.close();
    }

}
